home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / _ReplaceStringInFile.au3 < prev    next >
Text File  |  2007-09-08  |  681b  |  28 lines

  1. #include <File.au3>
  2.  
  3. $find = "BEFORE"
  4. $replace = "AFTER"
  5.  
  6. $filename = "C:\_ReplaceStringInFile.test"
  7.  
  8. $msg = "Hello Test " & $find & " Hello Test" & @CRLF
  9. $msg &= "Hello Test" & @CRLF
  10. $msg &= @CRLF
  11. $msg &= $find
  12.  
  13. FileWrite($filename, $msg )
  14.     
  15. msgbox(0,"BEFORE",$msg)
  16.  
  17. $retval = _ReplaceStringInFile($filename,$find,$replace)
  18. if $retval = -1 then
  19.     msgbox(0, "ERROR", "The pattern could not be replaced in file: " & $filename & " Error: " & @error)
  20.     exit
  21. else
  22.     msgbox(0, "INFO", "Found " & $retval & " occurances of the pattern: " & $find & " in the file: " & $filename)
  23. endif
  24.  
  25. $msg = FileRead($filename, 1000)
  26. msgbox(0,"AFTER",$msg)
  27. FileDelete($filename)
  28.